package com.android.universydroid.framework;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class WSIntegration {

	public int somar(int v1, int v2) throws IOException, XmlPullParserException {
		//Namespace e nome para o objeto SOAP
		SoapObject soap = new SoapObject("urn:CalculadoraService", "somar");
		//Adiciona os parametros para a soma
		soap.addProperty("v1", v1);
		soap.addProperty("v2", v2);
		//Cria o envelope com o objeto SOAP
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(soap);

		//Executa WS		
		HttpTransportSE transport = new HttpTransportSE("http://10.0.2.2:8080/WebCalculadora/services/Calculadora");
		transport.call("", envelope);
		//Recupera o resultado
		Object soma = envelope.getResponse();
		return Integer.parseInt(soma.toString());
	}
}
